#include <php.h>
#include "core_functions.h"

//core functions
PHP_FUNCTION(wpiPinMode)
{
    zend_long pin;
    zend_long mode;

	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_LONG(pin)
		Z_PARAM_LONG(mode)
	ZEND_PARSE_PARAMETERS_END();

    pinMode(pin, mode);
}

PHP_FUNCTION(wpiPullUpDnControl)
{
    zend_long pin;
    zend_long pud;

	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_LONG(pin)
		Z_PARAM_LONG(pud)
	ZEND_PARSE_PARAMETERS_END();

    pullUpDnControl(pin, pud);
}

PHP_FUNCTION(wpiDigitalWrite)
{
    zend_long pin;
    zend_long value;

	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_LONG(pin)
		Z_PARAM_LONG(value)
	ZEND_PARSE_PARAMETERS_END();

    digitalWrite(pin, value);
}

PHP_FUNCTION(wpiPwmWrite)
{
    zend_long pin;
    zend_long value;

	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_LONG(pin)
		Z_PARAM_LONG(value)
	ZEND_PARSE_PARAMETERS_END();

    digitalWrite(pin, value);
}

PHP_FUNCTION(wpiDigitalRead)
{
    zend_long pin;

	ZEND_PARSE_PARAMETERS_START(1, 1)
		Z_PARAM_LONG(pin)
	ZEND_PARSE_PARAMETERS_END();

    long ret = digitalRead(pin);
    RETURN_LONG(ret);
}

PHP_FUNCTION(wpiAnalogRead)
{
    zend_long pin;

	ZEND_PARSE_PARAMETERS_START(1, 1)
		Z_PARAM_LONG(pin)
	ZEND_PARSE_PARAMETERS_END();

    long ret = analogRead(pin);
    RETURN_LONG(ret);
}

PHP_FUNCTION(wpiAnalogWrite)
{
    zend_long pin;
    zend_long value;

	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_LONG(pin)
		Z_PARAM_LONG(value)
	ZEND_PARSE_PARAMETERS_END();

    analogWrite(pin, value);
}

//end core functions